package com.gscitysfy.cus.drain.modules.command.controller;

import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.modules.command.dto.ResourceDispatchDto;
import com.gscitysfy.cus.drain.modules.command.dto.SendMessageRequest;
import com.gscitysfy.cus.drain.modules.command.service.IResourceDispatchService;
import com.gscitysfy.cus.drain.modules.command.vo.ResourceDispatchQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author jiang_wen
 * @Date 2022/10/21 16:41
 * @Description TODO
 */
@Tag(name = "指挥调度 -> 资源调度")
@AllArgsConstructor
@RestController
@RequestMapping(value = "/resource")
public class ResourceDispatchController {

    private final IResourceDispatchService iResourceDispatchService;

    @Operation(summary = "获取资源调度列表详情")
    @GetMapping("/list")
    public Result<ResourceDispatchDto> list(ResourceDispatchQuery query) {
        return Result.content(iResourceDispatchService.fetchList(query));
    }

    @Operation(summary = "新增资源调度")
    @PostMapping
    public Result<Long> save(@RequestBody @Validated ResourceDispatchDto dto) {
        return Result.content(iResourceDispatchService.save(dto, true));
    }
    @Operation(summary = "选择调度方案")
    @GetMapping("/chooseScheme")
    public Result<ResourceDispatchDto> chooseScheme(ResourceDispatchQuery query) {
        return Result.content(iResourceDispatchService.fetchSchemeList(query));
    }
    @Operation(summary = "新增指令下发")
    @PostMapping("/instruct")
    public Result<Long> instruct(@RequestBody @Validated ResourceDispatchDto dto) {
        return Result.content(iResourceDispatchService.save(dto, false));
    }

    @Operation(summary = "发送短信")
    @PostMapping(value = "/sendMessage")
    public Result<Boolean> sendMessage(@RequestBody SendMessageRequest request) throws Exception {
        return Result.content(iResourceDispatchService.sendMessage(request));
    }
}
